package monopoly.View;


import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GridBagLayout;
import java.awt.Rectangle;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import monopoly.Model.Figur;
import monopoly.Model.Strasse;


/**
 * 
 */

/**
 * @author dpeters
 * 
 */
public class KaufenDialog extends JDialog {

    private static final long serialVersionUID = 1L;
    private JPanel            jContentPane     = null;
    private JButton           jButton          = null;
    private JButton           jButton1         = null;
    private JLabel            jLabel           = null;
   
    private int     aktuellCard = 0;
    private Figur   figur;
    private Strasse strasse;
    private ButtonActionListener aL ;
    private ButtonActionListenerHausKauf hausAL ;
    public Strasse getStrasse() {
        return strasse;
    }

    public void setJLabel( String label ) {
        jLabel.setText( label );
    }

    /**
     * @param owner
     */
    public KaufenDialog( Frame owner ) {
        super( owner );
        initialize();
    }

    public void schowKaufenDialog( Figur figur, Strasse strasse ) {
        this.figur = figur;
        this.strasse =strasse;
        this.aktuellCard = strasse.getId();
        setJLabel( strasse.getName() );
        aL.updateData( this.strasse,this.figur,this);
        this.setVisible( true );
    }

    public void schowHausKaufenDialog( Figur figur, Strasse strasse ) {
        this.figur = figur;
        this.strasse =strasse;
        this.aktuellCard = strasse.getId();
        setJLabel( strasse.getName() );
        hausAL.updateData( this.strasse,this.figur,this);
        this.setVisible( true );
    }    
    
    /**
     * This method initializes this
     * 
     * @return void
     */
    private void initialize() {
        this.setSize( 282, 400 );
        aL = new ButtonActionListener();
        this.setContentPane( getJContentPane() );
        this.setTitle( "Wolle kaufen??" );
        this.setLocationRelativeTo( this );
        this.setModalityType( Dialog.ModalityType.DOCUMENT_MODAL );   
    }

    /**
     * This method initializes jContentPane
     * 
     * @return javax.swing.JPanel
     */
    private JPanel getJContentPane() {
        if ( jContentPane == null ) {
            jLabel = new JLabel();
            jLabel.setBounds( new Rectangle( 18, 4, 238, 28 ) );
            jLabel.setHorizontalAlignment( SwingConstants.CENTER );
            jLabel.setHorizontalTextPosition( SwingConstants.CENTER );
            jLabel.setText( "Name" );
            jContentPane = new JPanel();
            jContentPane.setLayout( null );
            jContentPane.add( getJButton(), null );
            jContentPane.add( getJButton1(), null );
            jContentPane.add( new CardPanel(), null );
            jContentPane.add( jLabel, null );
        }
        return jContentPane;
    }

    /**
     * This method initializes jButton
     * 
     * @return javax.swing.JButton
     */
    private JButton getJButton() {
        if ( jButton == null ) {
            jButton = new JButton();
            jButton.setBounds( new Rectangle( 18, 332, 98, 27 ) );
            jButton.setText( "Ja" );
            jButton.setToolTipText( "" );
       
            jButton.addActionListener(aL);
        }
        return jButton;
    }

    /**
     * This method initializes jButton1
     * 
     * @return javax.swing.JButton
     */
    private JButton getJButton1() {
        if ( jButton1 == null ) {
            jButton1 = new JButton();
            jButton1.setBounds( new Rectangle( 159, 332, 98, 27 ) );
            jButton1.setText( "Nein" );
            jButton1.addActionListener( aL );
        }
        return jButton1;
    }

    class CardPanel extends JPanel {

        public CardPanel() {
            this.setLayout( new GridBagLayout() );
            this.setBounds( new Rectangle( 18, 38, 238, 290 ) );
        }

        public void paint( Graphics g ) {
            update( g );
        }

        public void update( Graphics g ) {
            g.drawImage( MediaFiles.getMediaFile().getCards()[aktuellCard], 1, 1, this );
        }
    }
}
